<?php

namespace app\index\controller;
use app\index\model\PohtoReport as PohtoReportModal;
use app\BaseController;
use think\Request;
class PhotoReport extends BaseController
{
    protected $middleware = [
        'Auth' => ['except' => []]
    ];

    public function submit(Request $request)
    {
        $params = $this->request->post(['photo_id', 'title', 'content', 'email']);
        $params['user_id'] = $request->user->id;
        $sql = new PohtoReportModal();
        $whereArr[] = ['photo_id', '=', $params['photo_id']];
        $whereArr[] = ['user_id', '=', $params['user_id']];
        $info = $sql->where($whereArr)->findOrEmpty();
        if(!$info->isEmpty()) {
            return  result()->fail("请耐心等待,不要重复举报", 500);
        }
        $sql->save($params);
        $newInfo = $sql->find($sql->id);
        return result()->success($newInfo);
    }
}